# -*- coding: utf-8 -*-
# created by Alberthch - 陈航  2021/7/15 19:32
# Description:怎样在两个字典中寻找相同点，比如相同的键，相同的值

a = {
    'x': 1,
    'y': 2,
    'z': 3
}

b = {
    'w': 10,
    'x': 11,
    'y': 2
}

# 共同点使用&，不同点使用-
# 同种类型，同样大小的可以使用数值运算和加减运算
print(type(a.keys()))  # <class 'dict_keys'>
print(type(a.keys() & b.keys()))  # <class 'set'>
print(type(a.keys() - b.keys()))  # <class 'set'>
print(type(a.items()))  # <class 'dict_items'>
print(type(a.items() & b.items()))  # <class 'set'>
print(type(a.items() - b.items()))  # <class 'set'>
print("=="*20)

print('Common keys:', a.keys() & b.keys())
print('Keys in a not in b:', a.keys() - b.keys())
print('(key,value) pairs in common:', a.items() & b.items())
print("=="*20)


# 过滤字典元素，修改字典元素
c = {key: a[key] for key in a.keys() - {'z', 'w'}}
print(c)
print("=="*20)


